--
-- Author: shunguo.chen
-- Date: 2017-09-01 12:31:51
--
-- Friend 好友／黑名单／陌生人

local fileName = string.getModeName(...)
local ClassRef = class(fileName)

function ClassRef:ctor(data, type)
	self.friendType = type or Enums.FriendType.friend
	if data then
		self:read(data)
	end

	-- 兼容以前可以通过 . 访问基础信息
	setmetatable(self, {
        __index = function(tab, key)
            local ret = rawget(tab, key)
            ret = rawget(tab.class, key)
            if not ret and tab["info"] then
                ret = tab["info"][key]
            end
            return ret
        end
    })
end

function ClassRef:read(data)
	-- dump(data, "Friend.read")
	self.online = data.online
	self.info = UserBaseInfo.new(data.userBaseInfo)
	self.info.online = data.online
	if rawget(data, "isHeadShiled") then
		self.isHeadShiled = data.isHeadShiled
	end
	if rawget(data, "wakeUpFrom") then
		self.wakeUpFrom = data.wakeUpFrom
	end
	
	if Enums.FriendType.msdk == self.friendType then
		if rawget(data, "vip") then
			self.msdkVip = data.vip
		end
		if rawget(data, "openId") then
			self.openId = data.openId
		end
	end
end

function ClassRef:isFriend()
	return self.friendType == Enums.FriendType.friend
end

function ClassRef:isBlack()
	return self.friendType == Enums.FriendType.black
end

function ClassRef:isStranger()
	return self.friendType == Enums.FriendType.stranger
end

function ClassRef:isApply()
	return self.friendType == Enums.FriendType.apply
end


function ClassRef:setRank(rank)
	self._rank = rank
end


function ClassRef:getRank()
	return self._rank or 1
end

function ClassRef:setHeadUrl(url, cacheName)
	if self.isHeadShiled then
		return
	end
	self._headUrl = url
	self._headUrlCacheName = cacheName
end

function ClassRef:getHeadUrl()
	return self._headUrl, self._headUrlCacheName
end

function ClassRef:setMsdkNickname(nickname)
	self._msdkNickname = nickname
end

function ClassRef:getMsdkNickname(nickname)
	return self._msdkNickname or ""
end

return ClassRef
